AI Verified

Name

New Badge on WooCommerce Products

About

Add a "New" Badge to recent Published Products in WooCommerce

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

https://www.codesnippets.cloud/snippet/ecommercehints/WooCommerce-Show-%E2%80%9CNEW%E2%80%9D-Badge-On-Newly-Added-Products

Codevault

Snug Snippets

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://snugsite.com.au/blog/

History

Last modified:

26/05/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

New Badge on WooCommerce Products

 
                    
1//Archive
2add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_product_archive_new_badge', 1 );
3function snug_product_archive_new_badge() {
4 global $product;
5 $days_to_show = 10;
6 $product_published_date = strtotime( $product->get_date_created() );
7 if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
8 echo '<span class="onsale">' . 'NEW' . '</span>';
9 }
10}
11 
12// Single product
13add_action( 'woocommerce_single_product_summary', 'ecommercehints_single_product_new_badge', 3 );
14function snug_single_product_new_badge() {
15 global $product;
16 $days_to_show = 10;
17 $product_published_date = strtotime( $product->get_date_created() );
18 if ( ( time() - ( 60 * 60 * 24 * $days_to_show ) ) < $product_published_date ) {
19 echo '<span class="onsale">' . 'NEW' . '</span>';
20 }
21}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Thank You Page Up-Sells

Added: 1 year ago

Last Updated: 1 year ago

Depending on your website theme, WooCommerce by default will only show product up-sells on the product page. Up-sells are products that you recommend instead of the currently viewed product. They are...

WooCommerce

AI Verified

0

WooCommerce Update Checkout Totals On Billing State County Change

Added: 1 year ago

Last Updated: 1 year ago

Are you writing a custom snippet which makes changes to the order totals based on the billing county

WooCommerce

AI Verified

1

WooCommerce Show Custom Text On Empty Cart Page

Added: 1 year ago

Last Updated: 2 months ago

If the user navigates to the cart page when there is nothing in their cart, they will see a cart notification, “Your cart is currently empty.” To change that particular cart notification, check out ou...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

1

Add Text Above WooCommerce Payment Options

Added: 1 year ago

Last Updated: 9 months ago

Show some text above the Payment Method Selection in WooCommerce Checkout.

WooCommerce

AI Verified

0

WooCommerce Breadcrumb Home Link and Anchor Text

Added: 3 months ago

Last Updated: 3 months ago

Change the default "Home" link in WooCOmmerce Breadcrumbs to a different URL with a different Anchor Text.

WooCommerce

AI Verified

0

New Badge on WooCommerce Products

Added: 1 year ago

Last Updated: 1 year ago

Add a "New" Badge to recent Published Products in WooCommerce